define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'ad/index',
                    add_url: 'ad/add',
                    edit_url: 'ad/edit',
                    del_url: 'ad/del',
                    multi_url: 'ad/multi',
                    table: 'ad',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'ad_id',
                sortName: 'ad_id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'ad_id', title: __('Ad_id')},
//                        {field: 'postion_id', title: __('Postion_id')},
                        {field: 'ad_title', title: __('Ad_title')},
                        {field: 'ad_img', title: __('Ad_img'),formatter: Table.api.formatter.image,operate:false},
                        {field: 'jump_type', title: __('Jump_type'), visible:false, searchList: {"0":__('不跳转'),"1":__('任务详情'),"2":__('url')}},
                        {field: 'jump_type_text', title: __('Jump_type'), operate:false},
                        {field: 'to_id', title: __('To_id'), operate:false},
                        {field: 'sort', title: __('排序值'), operate:false},
//                        {field: 'ad_link', title: __('Ad_link'), operate:false},
                        {field: 'starttime', title: __('Starttime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'endtime', title: __('Endtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
//                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
//                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
                $('#c-jump_type').bind('change',function(){
                    var obj = $(this);
                    console.log(obj.val());
                    $('.js-chage-input').find("input").val('');
                    $('.js-chage-input').hide();
                    if(obj.val() == '1'){
                        $('#js-task-no').show();
                    }else if(obj.val() == '2'){
                        $('#js-url').show();
                    }
                });
            }
        }
    };
    return Controller;
});